<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.util.*,java.io.*,java.sql.*,java.text.*, dbAccess.*"%>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content
-Type" content="text/html; charset=ISO-8859-1" />
<title>Doctor Create/Update Process</title>
<link rel="stylesheet" type="text/css" href="css_files/style.css" />
</head>
<body>
 <%
 
 	//create new doctor
 	Admin newAdmin = new Admin(session.getAttribute("Name").toString());
 	String action = request.getParameter("action");
 	
 	if ((action!= null) && action.equals("update"))
 	{
 		int adminId = Integer.parseInt(request.getParameter("adminId"));
 		newAdmin.setAdminId(adminId);
		DbAccess access = new DbAccess();
		String query = "select SIN from tbl_admin where (AdminId = " + adminId ;
				query += ") and IsDeleted = '0' ";
		
		String SIN = access.ExecuteScalar(access.connect(), query);
 		newAdmin.setSIN(Integer.parseInt(SIN));
		newAdmin.setPassword(request.getParameter("Password"));
 	}
 	if ((action != null) && (action.equals("add")))
 	{
		newAdmin.setSIN(Integer.parseInt(request.getParameter("SIN")));
		newAdmin.setPassword(request.getParameter("password"));
 	}

  
  //tbl_doctor
   //out.print(request.getParameter("docSIN"));
   //newDoc.setSIN(Integer.parseInt(request.getParameter("docSIN")));
   newAdmin.setFirstName(request.getParameter("firstName"));
   newAdmin.setLastName(request.getParameter("lastName"));
   newAdmin.setPhoneNum(request.getParameter("phone"));
   newAdmin.setHomeAddress(request.getParameter("homeAddress"));
   newAdmin.setPassword(request.getParameter("password"));
   newAdmin.setEmailAddress(request.getParameter("emailAddress"));
   
   
   //tbl_doctor
  newAdmin.setDateOfBirth((java.sql.Date.valueOf(request.getParameter("dateOfBirth").toString())));
  if (request.getParameter("gender").equals("male"))
  {
  	newAdmin.setGender("M");
  }
  else
  {
 	newAdmin.setGender("F");
  }
  //String Gender = request.getParameter("frmGender");
  
  if (newAdmin.registerAdmin(action))
  {
 	 out.print(newAdmin.getStatusMsg());
 	 newAdmin.setStatusMsg("");
  }
  else
  {
  	out.print("Failed to create Admin: " + newAdmin.getStatusMsg());
  	newAdmin.setStatusMsg("");
  }
  
  
  //String backHome = request.getParameter("callerId").toString() + ".jsp";
 %>
 <form id="frmback" action="adminHome.jsp">
 <input type="submit"  name="cmdAdminHome" id="cmdAdminHome" value="Back Home"/>
 </form>

</body>
</html>